package com.zpark.express.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> {
    private int code;
    private String message;
    private T resultData;
    //需要返回多个key
    private Map<String, Object> mapData;//多数据返回时

    /**
     * @Desc: 成功的结果集
     * @Date: 2020/7/17
     */
    public static Result success() {
        return customize(200, "success");
    }

    /**
    * @Desc: 自定义消息的成功结果集，
    * @Date: 2020/7/17
    */
    public static Result success(String message){
        return customize(200,message);
    }

    /**
     * @Desc: 自定义消息结果的成功结果集，
     * @Date: 2020/7/17
     */
    public static Result success(String message,Object data){
        return customize(200,message);
    }

    /**
     * @Desc: 失败的返回结果
     * @Date: 2020/7/17
     */

    public static Result fail() {
        return customize(ReusltCode.FAIL, "fail");
    }

    public static Result fail(String message) {
        return customize(ReusltCode.FAIL, message);
    }

    /**
     * @Desc: 自定的一个只有code和message的Result
     * @Date: 2020/7/17
     */
    public static Result customize(int code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }


    /**
    * @Desc: 成功的操作且要添加数据
    * @Date: 2020/7/17
    */

    public Result addResultOk(T resultData){
        Result result = new Result();
        result.setCode(ReusltCode.SUCCESS);
        result.setMessage("success");
        result.setResultData(resultData);
        return result;
    }



    public static Result addResultOk(Object resultData,String message){
        Result result = new Result();
        result.setCode(ReusltCode.SUCCESS);
        result.setMessage(message);
        result.setResultData(resultData);
        return result;
    }


}
